﻿Shader "Running/normalDepth"
{
	Properties
	{
	}
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 100
		Pass {

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#include "UnityCG.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float3 normal : NORMAL;
			};

			struct v2f
			{
				float4 vertex : SV_POSITION;
				float2 outDepth : TEXCOORD0;
			};
			v2f vert(appdata v)
			{
				v2f o;
				float4x4 mat1 = UNITY_MATRIX_MV;
				float3 offsetPos = (v.vertex.xyz - v.normal);
				o.vertex = mul(UNITY_MATRIX_P, mul(mat1, float4(v.normal, 1)) + float4(offsetPos, 0));
				o.outDepth = o.vertex.zw;
				return o;
			}

			fixed4 frag(v2f i) : SV_Target
			{
				float finalDepth = i.outDepth.x / i.outDepth.y;
				fixed4 col = fixed4(finalDepth, finalDepth, finalDepth, 1);
			return col;
			}
			ENDCG
		}

	}
}
